/*
 * Copyright (c) 2009-2024 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*============================ INCLUDES ======================================*/

#define __USER_SCENE0_IMPLEMENT__
#include "arm_2d_scenes.h"

#if defined(RTE_Acceleration_Arm_2D_Helper_PFB)

#ifdef RTE_Acceleration_Arm_2D_Scene0

#include <stdlib.h>
#include <string.h>

#if defined(__clang__)
#   pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wunknown-warning-option"
#   pragma clang diagnostic ignored "-Wreserved-identifier"
#   pragma clang diagnostic ignored "-Wsign-conversion"
#   pragma clang diagnostic ignored "-Wpadded"
#   pragma clang diagnostic ignored "-Wcast-qual"
#   pragma clang diagnostic ignored "-Wcast-align"
#   pragma clang diagnostic ignored "-Wmissing-field-initializers"
#   pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#   pragma clang diagnostic ignored "-Wmissing-prototypes"
#   pragma clang diagnostic ignored "-Wunused-variable"
#   pragma clang diagnostic ignored "-Wgnu-statement-expression"
#   pragma clang diagnostic ignored "-Wdeclaration-after-statement"
#   pragma clang diagnostic ignored "-Wunused-function"
#   pragma clang diagnostic ignored "-Wmissing-declarations"
#   pragma clang diagnostic ignored "-Wimplicit-int-conversion" 
#elif __IS_COMPILER_ARM_COMPILER_5__
#   pragma diag_suppress 64,177
#elif __IS_COMPILER_IAR__
#   pragma diag_suppress=Pa089,Pe188,Pe177,Pe174
#elif __IS_COMPILER_GCC__
#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wformat="
#   pragma GCC diagnostic ignored "-Wpedantic"
#   pragma GCC diagnostic ignored "-Wunused-function"
#   pragma GCC diagnostic ignored "-Wunused-variable"
#   pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#endif

/*============================ MACROS ========================================*/

#if __GLCD_CFG_COLOUR_DEPTH__ == 8

#   define c_tileCMSISLogo          c_tileCMSISLogoGRAY8

#elif __GLCD_CFG_COLOUR_DEPTH__ == 16

#   define c_tileCMSISLogo          c_tileCMSISLogoRGB565

#elif __GLCD_CFG_COLOUR_DEPTH__ == 32

#   define c_tileCMSISLogo          c_tileCMSISLogoCCCA8888
#else
#   error Unsupported colour depth!
#endif

/*============================ MACROFIED FUNCTIONS ===========================*/
#undef this
#define this (*ptThis)

/*============================ TYPES =========================================*/
/*============================ GLOBAL VARIABLES ==============================*/

extern const arm_2d_tile_t c_tileCMSISLogo;
extern const arm_2d_tile_t c_tileCMSISLogoMask;
extern const arm_2d_tile_t c_tileCMSISLogoA2Mask;
extern const arm_2d_tile_t c_tileCMSISLogoA4Mask;
/*============================ PROTOTYPES ====================================*/
/*============================ LOCAL VARIABLES ===============================*/
//void icon_list_next();
void icon_list_run(arm_2d_scene_t *ptScene);
void  draw_string_2d(uint16_t iX,uint16_t iY,char font_size,char *strin,
    void *pTarget,                                  
                                const arm_2d_tile_t *ptTile);
/*! define dirty regions */
IMPL_ARM_2D_REGION_LIST(s_tDirtyRegions, static)

    /* a dirty region to be specified at runtime*/
    ADD_REGION_TO_LIST(s_tDirtyRegions,
        0  /* initialize at runtime later */
    ),
    
    /* add the last region:
        * it is the top left corner for text display 
        */
    ADD_LAST_REGION_TO_LIST(s_tDirtyRegions,
        .tLocation = {
            .iX = 0,
            .iY = 0,
        },
        .tSize = {
            .iWidth = 0,
            .iHeight = 8,
        },
    ),

END_IMPL_ARM_2D_REGION_LIST(s_tDirtyRegions)

/*============================ IMPLEMENTATION ================================*/

static void __on_scene0_load(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static void __after_scene0_switching(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}

static void __on_scene0_depose(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);
    
    ptScene->ptPlayer = NULL;
    
    /* reset timestamp */
    arm_foreach(int64_t,this.lTimestamp, ptItem) {
        *ptItem = 0;
    }

    if (!this.bUserAllocated) {
        __arm_2d_free_scratch_memory(ARM_2D_MEM_TYPE_UNSPECIFIED, ptScene);
    }
}

/*----------------------------------------------------------------------------*
 * Scene 0                                                                    *
 *----------------------------------------------------------------------------*/

static void __on_scene0_background_start(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);
    
    

}

static void __on_scene0_background_complete(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}


static void __on_scene0_frame_start(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);
    icon_list_run( ptScene);//===================
}

static void __on_scene0_frame_complete(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

#if 1
    /* switch to next scene after 3s */
    if (arm_2d_helper_is_time_out(3000, &this.lTimestamp[0])) {
        //arm_2d_scene_player_switch_to_next_scene(ptScene->ptPlayer);
        //icon_list_next();
    }
#endif
}

static void __before_scene0_switching_out(arm_2d_scene_t *ptScene)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)ptScene;
    ARM_2D_UNUSED(ptThis);

}
extern const arm_2d_tile_t c_tileCar24A1Mask;
extern const arm_2d_tile_t c_tilebookA2Mask;
void icon_list_init();
void  draw_icon(void *pTarget,                                  
                                const arm_2d_tile_t *ptTile,
                                arm_2d_region_t my_region,    
                                bool bIsNewFrame);
static
IMPL_PFB_ON_DRAW(__pfb_draw_scene0_handler)
{
    user_scene_0_t *ptThis = (user_scene_0_t *)pTarget;
    arm_2d_size_t tScreenSize = ptTile->tRegion.tSize;

    ARM_2D_UNUSED(ptTile);
    ARM_2D_UNUSED(bIsNewFrame);
    ARM_2D_UNUSED(tScreenSize);
    arm_2d_fill_colour(ptTile, NULL, GLCD_COLOR_BLACK);
    arm_2d_canvas(ptTile, __top_canvas) {
        
        draw_icon(pTarget,                                  
                  ptTile,
                  __top_canvas,    
                  bIsNewFrame);
         
        
    /*-----------------------draw the foreground begin-----------------------*/
         
        arm_2d_region_t my_region={
             .tLocation = {
            .iX = 2,
            .iY = 14,
        },
        .tSize = {
            .iWidth = 40,
            .iHeight = 40,
        },
        };
//        arm_2d_fill_colour_with_a1_mask(ptTile, 
//                                            &my_region, 
//                                            &c_tileCar24A1Mask, 
//                                            (__arm_2d_color_t){GLCD_COLOR_WHITE});
       
//       arm_2d_fill_colour_with_a8_mask(ptTile, 
//                                            &my_region, 
//                                            &c_tilemusicGRAY8, 
//                                            (__arm_2d_color_t){GLCD_COLOR_WHITE});
//        my_region.tLocation.iX += 42;
//        arm_2d_fill_colour_with_a8_mask(ptTile, 
//                                            &my_region, 
//                                            &c_tilebookGRAY8, 
//                                            (__arm_2d_color_t){GLCD_COLOR_WHITE});  
//         my_region.tLocation.iX += 42;
//        arm_2d_fill_colour_with_a8_mask(ptTile, 
//                                            &my_region, 
//                                            &c_tilewordGRAY8, 
//                                            (__arm_2d_color_t){GLCD_COLOR_WHITE});                                            
        /* draw text at the top-left corner */

        arm_lcd_text_set_target_framebuffer((arm_2d_tile_t *)ptTile);
        arm_lcd_text_set_font(&ARM_2D_FONT_6x8.use_as__arm_2d_font_t);
        arm_lcd_text_set_draw_region(NULL);
        arm_lcd_text_set_colour(GLCD_COLOR_WHITE, GLCD_COLOR_BLACK);
        arm_lcd_text_location(0,0);
        //arm_lcd_puts("Scene 0");
        
        //draw_string_2d(0,0,16,"玩转arm-2d",  pTarget,  ptTile);

    /*-----------------------draw the foreground end  -----------------------*/
    }
    ARM_2D_OP_WAIT_ASYNC();

    return arm_fsm_rt_cpl;
}

ARM_NONNULL(1)
user_scene_0_t *__arm_2d_scene0_init(   arm_2d_scene_player_t *ptDispAdapter, 
                                        user_scene_0_t *ptThis)
{
    bool bUserAllocated = false;
    assert(NULL != ptDispAdapter);

    s_tDirtyRegions[dimof(s_tDirtyRegions)-1].ptNext = NULL;

    /* get the screen region */
    arm_2d_region_t tScreen
        = arm_2d_helper_pfb_get_display_area(
            &ptDispAdapter->use_as__arm_2d_helper_pfb_t);

    /* initialise dirty region 0 at runtime
     * this demo shows that we create a region in the centre of a screen(320*240)
     * for a image stored in the tile c_tileCMSISLogoMask
     */
    arm_2d_align_centre(tScreen, c_tileCMSISLogoMask.tRegion.tSize) {
        s_tDirtyRegions[0].tRegion = __centre_region;
    }

    s_tDirtyRegions[dimof(s_tDirtyRegions)-1].tRegion.tSize.iWidth 
                                                        = tScreen.tSize.iWidth;
    
    if (NULL == ptThis) {
        ptThis = (user_scene_0_t *)
                    __arm_2d_allocate_scratch_memory(   sizeof(user_scene_0_t),
                                                        __alignof__(user_scene_0_t),
                                                        ARM_2D_MEM_TYPE_UNSPECIFIED);
        assert(NULL != ptThis);
        if (NULL == ptThis) {
            return NULL;
        }
    } else {
        bUserAllocated = true;
    }
    memset(ptThis, 0, sizeof(user_scene_0_t));

    *ptThis = (user_scene_0_t){
        .use_as__arm_2d_scene_t = {

            /* the canvas colour */
            .tCanvas = {GLCD_COLOR_WHITE}, 

            /* Please uncommon the callbacks if you need them
             */
            .fnOnLoad       = &__on_scene0_load,
            .fnScene        = &__pfb_draw_scene0_handler,
            //.fnAfterSwitch  = &__after_scene0_switching,

            /* if you want to use predefined dirty region list, please uncomment the following code */
            //.ptDirtyRegion  = (arm_2d_region_list_item_t *)s_tDirtyRegions,
            

            //.fnOnBGStart    = &__on_scene0_background_start,
            //.fnOnBGComplete = &__on_scene0_background_complete,
            .fnOnFrameStart = &__on_scene0_frame_start,
            //.fnBeforeSwitchOut = &__before_scene0_switching_out,
            .fnOnFrameCPL   = &__on_scene0_frame_complete,
            .fnDepose       = &__on_scene0_depose,

            .bUseDirtyRegionHelper = false,
        },
        .bUserAllocated = bUserAllocated,
    };

    /* ------------   initialize members of user_scene_0_t begin ---------------*/


    /* ------------   initialize members of user_scene_0_t end   ---------------*/

    arm_2d_scene_player_append_scenes(  ptDispAdapter, 
                                        &this.use_as__arm_2d_scene_t, 
                                        1);
                                        
    icon_list_init();
    return ptThis;
}



//=====================================================================
#include "key.h"
extern const arm_2d_tile_t c_tilebookGRAY8; 
extern const arm_2d_tile_t c_tilemusicGRAY8;
extern const arm_2d_tile_t c_tilewordGRAY8;

enum icon_list_num{
    ICON_MUSIC_NUM = 0,
    ICON_BOOK_NUM,
    ICON_WORD_NUM,
};
const arm_2d_tile_t *my_icon[3] = {
    [0] = &c_tilemusicGRAY8,
    [1] = &c_tilebookGRAY8,
    [2] = &c_tilewordGRAY8,
};
const char *my_icon_string[3] = {
    [0] = " 音乐 ",
    [1] = "电子书",
    [2] = "单词卡",
};

typedef struct icon_list_t{
    char current_entry;
    char total_entries_num;
}icon_list_t;
icon_list_t my_icon_list;
void icon_list_init(){
    my_icon_list.current_entry = 1;
    my_icon_list.total_entries_num = 3;
}
void icon_list_next(){
    my_icon_list.current_entry++;
    my_icon_list.current_entry = my_icon_list.current_entry % my_icon_list.total_entries_num;
}
void icon_list_previous(){
    if(my_icon_list.current_entry == 0){
        my_icon_list.current_entry =  my_icon_list.total_entries_num;
    }
    my_icon_list.current_entry--;
}
void icon_list_run(arm_2d_scene_t *ptScene){
    char key;
    key = get_g_key_num();
    if(key){
        switch (key){
            case 1:
                icon_list_previous();
            break;
            case 3:
                icon_list_next();
            break;
            case 2:
                //icon_list_next();
                if(ICON_BOOK_NUM == my_icon_list.current_entry){
                    __arm_2d_scene1_init( &DISP0_ADAPTER ,NULL);
                    arm_2d_scene_player_switch_to_next_scene(ptScene->ptPlayer);
                }
                if(ICON_WORD_NUM == my_icon_list.current_entry){
                    __arm_2d_scene2_init( &DISP0_ADAPTER ,NULL);
                    arm_2d_scene_player_switch_to_next_scene(ptScene->ptPlayer);
                }
            break;
        }
        set_g_key_num(0);
    }
}
void  draw_icon(void *pTarget,                                  
                                const arm_2d_tile_t *ptTile,
                                arm_2d_region_t my_region,    
                                bool bIsNewFrame){
    arm_2d_dock_top( my_region,  50 ) {
        //__top_region   
        arm_2d_dock_vertical( __top_region,  40 ) {
            //__vertical_region   
            arm_2d_align_centre(__vertical_region, 40,40 ) { 
                arm_2d_fill_colour_with_a8_mask(ptTile, 
                                        &__centre_region, 
                                        my_icon[my_icon_list.current_entry], 
                                        (__arm_2d_color_t){GLCD_COLOR_WHITE}); 
                __centre_region.tLocation.iX -= 1;   
                __centre_region.tLocation.iY -= 1; 
                __centre_region.tSize.iHeight += 2;
                __centre_region.tSize.iWidth += 2;                            
                arm_2d_filter_reverse_colour(ptTile, 
                                        &__centre_region);                        
            }
            arm_2d_dock_left(__vertical_region, 40){
                char num;
                __left_region.tLocation.iX -= 10;
                if(0 == my_icon_list.current_entry){
                    num = my_icon_list.total_entries_num;
                }else{
                    num = my_icon_list.current_entry;
                }
                arm_2d_fill_colour_with_a8_mask(ptTile, 
                                        &__left_region, 
                                        my_icon[num - 1], 
                                        (__arm_2d_color_t){GLCD_COLOR_WHITE}); 
            }
            arm_2d_dock_right(__vertical_region, 40){
                __right_region.tLocation.iX += 10;
                arm_2d_fill_colour_with_a8_mask(ptTile, 
                                        &__right_region, 
                                        my_icon[(my_icon_list.current_entry + 1) % my_icon_list.total_entries_num ], 
                                        (__arm_2d_color_t){GLCD_COLOR_WHITE}); 
            }
        }                
    }
    arm_2d_dock_bottom(my_region,  20){
        arm_2d_align_centre(__bottom_region, 16*3,16 ) { 
            draw_string_2d(__centre_region.tLocation.iX,
            __centre_region.tLocation.iY,
            16,my_icon_string[my_icon_list.current_entry],  pTarget,  ptTile);
        }
        
    
    }
                                    
}
                                
//======================================================================
#include "ff.h"
#define  FONT12_FON  "/font/GBK12.FON"
#define  FONT16_FON  "/font/GBK16.FON"
#define  FONT24_FON  "/font/GBK24.FON"
#include "myoled.h"

arm_2d_tile_t c_tilebcharGRAY8 = {
    .tRegion = {
        .tSize = {
            .iWidth = 12,
            .iHeight = 12,
        },
    },
    .tInfo = {
        .bIsRoot = true,
        .bHasEnforcedColour = true,
        .tColourInfo = {
            .chScheme = ARM_2D_COLOUR_GRAY8,
        },
    },
    //.pchBuffer = (uint8_t*)c_bmpbookGRAY8,
};
void draw_char_2d(uint16_t iX,uint16_t iY,char font_size,char iWidth,unsigned char * chardata,
            void *pTarget,                                  
            const arm_2d_tile_t *ptTile){
    c_tilebcharGRAY8.tRegion.tSize.iHeight = font_size;
        c_tilebcharGRAY8.tRegion.tSize.iWidth  = iWidth;
        c_tilebcharGRAY8.pchBuffer = chardata;
        arm_2d_region_t my_region;
        my_region.tLocation.iX = iX;
        my_region.tLocation.iY = iY;
        my_region.tSize.iHeight = font_size;
        my_region.tSize.iWidth  = iWidth;
        arm_2d_fill_colour_with_a8_mask(ptTile, 
                                        &my_region, 
                                        &c_tilebcharGRAY8, 
                                        (__arm_2d_color_t){GLCD_COLOR_WHITE}); 
}
void  draw_char_EN_2d(uint16_t iX,uint16_t iY,char font_size,char ch,void *pTarget,                                  
                                const arm_2d_tile_t *ptTile){
    uint8_t chardata[24*24]; 
    uint16_t temp, t1, t;;
    int csize;// = (font_size/8+((font_size%8)?1:0))*(font_size/2);  //得到字体一个字符对应点阵集所占的字节数
    uint32_t y0 = iY, x0=iX;
    
    ch = ch - ' ';	//得到偏移后的值
    
    if(font_size == 12) {
        for(int x = 0; x < 6; x++){
            for(int y = 0; y < 2;y++){
                temp=asc2_1206[ch][x*2 + y]; 	 	//调用1608字体
                for(int n = 0; n < 8;n++){
                    if(temp&0x80){
                        chardata[(y*8+n) * 6 +x] = 0xff;
                    }else{
                        chardata[(y*8+n) * 6 +x] = 0x00;
                    }
                    temp <<= 1;
                }
            }
        
        }
        //OLED_DrawBitmap(x0, y0, 6, 16, chardata);
        draw_char_2d(x0, y0,12,6,chardata, pTarget, ptTile);
 
        
	}else if(font_size == 16) {
        for(int x = 0; x < 8; x++){
            for(int y = 0; y < 2;y++){
                temp=asc2_1608[ch][x*2 + y]; 	 	//调用1608字体
                for(int n = 0; n < 8;n++){
                    if(temp&0x80){
                        chardata[(y*8+n) * 8 +x] = 0xff;
                    }else{
                        chardata[(y*8+n) * 8 +x] = 0x00;
                    }
                    temp <<= 1;
                }
            }
        
        }
        //OLED_DrawBitmap(x0, y0, 8, 16, chardata);
        draw_char_2d(x0, y0,16,8,chardata, pTarget, ptTile);
	}
    else  {
        for(int x = 0; x < 12; x++){
            for(int y = 0; y < 3;y++){
                temp=asc2_2412[ch][x*3 + y]; 	 	//调用2412字体
                for(int n = 0; n < 8;n++){
                    if(temp&0x80){
                        chardata[(y*8+n) * 12 +x] = 0xff;
                    }else{
                        chardata[(y*8+n) * 12 +x] = 0x00;
                    }
                    temp <<= 1;
                }
            }
        
        }
        //OLED_DrawBitmap(x0, y0, 12, 24, chardata);
        draw_char_2d(x0, y0,24,12,chardata, pTarget, ptTile);
	 
	}
}
                                
void  draw_char_CN_2d(uint16_t iX,uint16_t iY,char font_size,char *ch,FIL *fil,void *pTarget,                                  
                                const arm_2d_tile_t *ptTile){
    uint8_t qh,ql;					  
	uint32_t foffset, rd_len;
	int i, ret;	 
    uint8_t len;
    uint8_t out_buff[3*24]; 
    
	qh = *ch;
	ql= *(++ch);
	if(qh<0x81||ql<0x40||ql==0xff||qh==0xff)//非常用汉字
	{   		    
//	    for(i=0;i<len;i++)
//			*out_buff++ = 0x00;      //填充满格
//	    return -1;
	}          
	if(ql<0x7f)
		ql-=0x40;//注意!
	else
		ql-=0x41;
	qh-=0x81;
    
    if(font_size == 12){
        len = 24;
    }else if(font_size == 16){
        len = 32;
    }else{
        len = 24*3;
    }
	
	foffset = ((uint32_t)190*qh+ql)*len;	  //得到字库中的字节偏移量
	ret = f_lseek(fil, foffset);
    if(ret != FR_OK)
	{
//	    for(i=0;i<len;i++)
//			*out_buff++ = 0x00;      //填充满格
//	    return -2;	
	}
    ret = f_read(fil, out_buff, len, &rd_len);
    
    if(ret!=FR_OK || rd_len!=len)
	{
//	    for(i=0;i<len;i++)
//			*out_buff++ = 0x00;      //填充满格
//	    return -3;		
	}
    
    uint32_t y0 = iY, x0=iX;
    uint8_t chardata[24*24]; 
    uint8_t temp;
    if(font_size == 12){
        //len = 24;
    }else if(font_size == 16){
        for(int x = 0; x < 16; x++){
            for(int y = 0; y < 2;y++){
                temp=out_buff[x*2 + y]; 	 	//调用1608字体
                for(int n = 0; n < 8;n++){
                    if(temp&0x80){
                        chardata[(y*8+n) * 16 +x] = 0xff;
                    }else{
                        chardata[(y*8+n) * 16 +x] = 0x00;
                    }
                    temp <<= 1;
                }
            }
        
        }
         
        draw_char_2d(x0, y0,16,16,chardata, pTarget, ptTile);
    }else{
        for(int x = 0; x < 24; x++){
            for(int y = 0; y < 3;y++){
                temp=out_buff[x*3 + y]; 	 	//调用1608字体
                for(int n = 0; n < 8;n++){
                    if(temp&0x80){
                        chardata[(y*8+n) * 24 +x] = 0xff;
                    }else{
                        chardata[(y*8+n) * 24 +x] = 0x00;
                    }
                    temp <<= 1;
                }
            }
        
        }
         
        draw_char_2d(x0, y0,24,24,chardata, pTarget, ptTile);
    }
}
void  draw_string_2d(uint16_t iX,uint16_t iY,char font_size,char *strin,
    void *pTarget,                                  
                                const arm_2d_tile_t *ptTile){
    int exist_hanzi = 0; 
    //int size = 24;
    const char *fname;
    FIL fil;
    uint8_t *draw_str;
    uint16_t x = iX;
        
    if(font_size == 12)
        fname = FONT12_FON;
    else if(font_size == 16)
        fname = FONT16_FON;
    else
        fname = FONT24_FON;
    if(f_open(&fil, fname, FA_READ) != FR_OK)
        return ;
    
    draw_str = (uint8_t *)strin;
    
    while(*draw_str != 0)
	{
		if(*draw_str < 0x80)
		{	//字符
            //			if((*p<='~') && (*p>=' '))	//判断是不是非法字符!
            //			{
			draw_char_EN_2d(x,iY,font_size,*draw_str,pTarget,ptTile);
			draw_str++;
            x += (font_size>>1);
            //			}
		}
		else
		{	//汉字
			draw_char_CN_2d(x,iY,font_size,draw_str,&fil,pTarget,ptTile);
			draw_str += 2;
            x += font_size;
		}
	}
	
	
	f_close(&fil);
	
	
}

#if defined(__clang__)
#   pragma clang diagnostic pop
#endif

#endif

#endif

